﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.DAO;
using System.Data;

/// <summary>
/// Summary description for SectorController
/// </summary>
/// 
namespace br.com.SistemaChamados.Controller
{
    public class SectorController
    {
        public List<Sector> GetSectorsByUnit(Sector sector)
        {
            List<Sector> listSector = null;
            SectorDAO sectorDAO = null;
            try
            {
                sectorDAO = new SectorDAO();
                listSector = sectorDAO.GetSectorsByUnit(sector);
                if (listSector != null)
                {
                    return listSector;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
                throw ex;
            }
        }

        public EnumGenericState InsertSector(Sector sector)
        {
            EnumGenericState resultSector = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                SectorDAO sectorDAO = new SectorDAO();
                resultSector = sectorDAO.InsertSector(sector);
            }
            catch (Exception ex)
            {
                resultSector = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return resultSector;
        }

        public EnumGenericState UpdateSector(Sector sector)
        {
            EnumGenericState resultSector = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                SectorDAO sectorDAO = new SectorDAO();
                resultSector = sectorDAO.UpdateSector(sector);
            }
            catch (Exception ex)
            {
                resultSector = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return resultSector;
        }
        public List<Sector> GetSectors()
        {
            List<Sector> listSector = null;
            SectorDAO sectorDAO = null;
            try
            {
                sectorDAO = new SectorDAO();
                listSector = sectorDAO.GetSectors();
                if (listSector != null)
                {
                    return listSector;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
                throw ex;
            }
        }
        public Sector GetSector(Sector sector)
        {
            Sector resultSector = null;
            SectorDAO sectorDAO = null;
            try
            {
                sectorDAO = new SectorDAO();
                resultSector = sectorDAO.GetSector(sector);
                if (resultSector != null)
                {
                    return resultSector;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
                throw ex;
            }
        }
        public EnumGenericState DeleteSector(Sector sector)
        {
            EnumGenericState resultSector = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                SectorDAO sectorDAO = new SectorDAO();
                resultSector = sectorDAO.DeleteSector(sector);
            }
            catch (Exception ex)
            {
                resultSector = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return resultSector;
        }
        
        public List<Sector> ListSectorByUnit(Sector sector){
            List<Sector> resultSector = null;
            SectorDAO sectorDAO = null;
            try
            {
                sectorDAO = new SectorDAO();
                resultSector = sectorDAO.GetSectorsByUnit(sector);
                if (resultSector != null)
                {
                    return resultSector;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }

        public SectorController()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}